﻿var Message = {
    OKFunction: null,
    CancelFunction: null,
    YesFunction: null,
    NoFunction: null
}

// Close MessageBox
Message.Close = function () {
    $('#divMessage').html('');
    $('#divMessage').remove();
    $('#divMessage').dialog('destroy').remove();
}

//Open MessageBox
Message.Show = function (text, messageBoxButtons, messagetype, defaultButton, param) {

    var iconUrl = GetVirtualPath('/Images/information.png');
    //Set icon image
    if (messagetype == Message.MessageType.Confirm) {
        var iconUrl = GetVirtualPath('/Images/information.png');
    }
    else if (messagetype == Message.MessageType.Error) {
        var iconUrl = GetVirtualPath('/Images/error.png');
    }
    else if (messagetype == Message.MessageType.Warning) {
        var iconUrl = GetVirtualPath('/Images/warning.png');
    }

    var div = '<div id="divMessage"><img id="imgicon" src="'
        + iconUrl + '" alt="Smiley face" height="42" width="42" style="float: left;padding-right: 5px;"><p id="txtMessage"'
        + 'style=" color: #58595B;float: left;text-align: left; width: 85%;">'
        + text + '</p><div class="clear-both"></div></div>';

    var buttons;
    if (messageBoxButtons == Message.MessageBoxButtons.YesNo) {
        buttons = {
            "Yes": function () { Message.Close(); if (Message.YesFunction != null) { Message.YesFunction(); Message.YesFunction = null; } },
            "No": function () { if (Message.NoFunction != null) { Message.NoFunction(); Message.NoFunction = null; } Message.Close(); }

        }
    } else if (messageBoxButtons == Message.MessageBoxButtons.OKCancel) {
        buttons = {
            "OK": function () { if (Message.OKFunction != null) { Message.OKFunction(); Message.OKFunction = null; } Message.Close(); },
            "Cancel": function () { if (Message.CancelFunction != null) { Message.CancelFunction(); Message.CancelFunction = null; } Message.Close(); }
        }
    }

    else if (messageBoxButtons == Message.MessageBoxButtons.YesNoCancel) {
        buttons = {
            "Yes": function () { Message.Close(); if (Message.YesFunction != null) { Message.YesFunction(); Message.YesFunction = null; } },
            "No": function () { if (Message.NoFunction != null) { Message.NoFunction(); Message.NoFunction = null; } Message.Close(); },
            "Cancel": function () { if (Message.CancelFunction != null) { Message.CancelFunction(); Message.CancelFunction = null; } Message.Close(); }
        }
    } else if (messageBoxButtons == Message.MessageBoxButtons.OK) {
        buttons = {
            "OK": function () { if (Message.OKFunction != null) { Message.OKFunction(); Message.OKFunction = null; } Message.Close(); }
        }

    }

    var result = $(div).dialog({

        autoOpen: false,
        width: 425,
        height: 'auto',
        modal: true,
        resizable: false,
        buttons: buttons
    });
    result.dialog('open');
    //Set title of messagebox
    $('.ui-dialog .ui-dialog-titlebar:last').append(messagetype);

}

Message.MessageBoxButtons = {
    // Summary:
    //     The message box contains an OK button.
    OK: 0,
    //
    // Summary:
    //     The message box contains OK and Cancel buttons.
    OKCancel: 1,
    //
    // Summary:
    //     The message box contains Abort, Retry, and Ignore buttons.
    AbortRetryIgnore: 2,
    //
    // Summary:
    //     The message box contains Yes, No, and Cancel buttons.
    YesNoCancel: 3,
    //
    // Summary:
    //     The message box contains Yes and No buttons.
    YesNo: 4,
    //
    // Summary:
    //     The message box contains Retry and Cancel buttons.
    RetryCancel: 5
}

Message.ButtonValue = {
    OK: 1,
    Cancel: 2,
    Yes: 3,
    No: 4,
    Abort: 5,
    Retry: 6,
    Ignore: 7
}
Message.MessageType =
{
    Warning: "Warning",
    Confirm: "Confirm",
    Error: "Error",
    Information: "Information",
    Question: "Question"
}